package com.chinasofti.java8.demo04;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;


public class TestStream2 {
    /*
    allMatch   检测是否有匹配元素
    anyMatch   检测是否至少匹配一个元素
    noneMatch  检测是否没有匹配的元素
    findFirst  返回第一个元素
    findAny    返回当前流中任意元素
    count      返回流中元素总个数
    max        返回最大值
    min        返回最小值

     */
    List<Employee> emps = Arrays.asList(
              new Employee(101, "张三", 18, 9999.99)
            , new Employee(102, "李四", 59, 6666.66)
            , new Employee(103, "王五", 28, 3333.33)
            , new Employee(104, "赵六", 8, 7777.7)
            , new Employee(105, "田七", 38, 5555.55)
            , new Employee(105, "田七", 38, 5555.55)
    );
    @Test
    public  void test1(){
        Optional<Employee> op =
                emps.stream().sorted((e1,e2)->Double.compare
                        (e1.getSalary(), e2.getSalary())).findFirst();
        System.out.println(op.get());
    }
    @Test
    public  void test2(){
        Stream<Employee> stream =
                emps.stream().filter((e)->e.getAge()>35);
        long count = stream.count();
        System.out.println(count);
        //注意：流进行了终止操作,不能再次使用
        //stream.map(Employee::getSalary).max(Double::compareTo);
    }

}
